<script setup lang="ts">
import { onMounted, ref } from "vue";
import { routes } from "./router/index";
import { RouterView } from "vue-router";
const title = ref("");
onMounted(() => {
  title.value = "首页";
});

function handleClick(child, router) {
  console.log(child, router);
  title.value = child.meta.title;
}
</script>

<template>
  <el-container style="height: 100vh; width: 100vw">
    <el-aside width="200px">
      <el-menu
        default-active="$route.path"
        router
        class="el-menu-vertical-demo"
      >
        <div :item="route" :key="route.path" v-for="(route, index) in routes">
          <el-sub-menu :index="index">
            <template #title>
              <span>{{ route.meta.title }}</span>
            </template>
            <div
              :item="child.name"
              :key="child.path"
              v-for="child in route.children"
            >
              <el-menu-item
                :index="route.path + '/' + child.path"
                @click="handleClick(child, route)"
              >
                <i class="el-icon-message"></i>
                <span slot="title">{{ child.meta.title }}</span>
              </el-menu-item>
            </div>
          </el-sub-menu>
        </div>
      </el-menu>
    </el-aside>
    <el-container
      ><el-header height="60px">
        <el-row justify="center">
          {{ title }}
        </el-row>
      </el-header>
      <el-main class="main-content">
        <RouterView></RouterView>
      </el-main>
      <el-footer height="60px">Footer</el-footer>
    </el-container>
  </el-container>
</template>

<style scoped>
.main-content {
  width: calc(100vw - 220px);
  height: calc(100vh - 140px);
  overflow: hidden;
}
</style>
